<template>
  <div class="app-container">
    <!-- 查询 -->
    <el-form :model="queryParams" ref="queryRefs" :inline="true">
      <el-form-item label="流程名称" prop="noticeTitle">
        <el-input
          v-model="queryParams.flowName"
          placeholder="请输入流程名称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作列 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="tableData" style="width: 100%">
      <!-- <el-table-column type="index" label="序号" :index="indexMethod" align="center"/> -->
      <el-table-column prop="id" v-if="false" />
      <el-table-column prop="imgUrl" label="流程图片" align="center">
        <template #default="scope">
          <div
            style="
              display: flex;
              align-items: center;
              width: 50px;
              height: 50px;
              margin-left: auto;
              margin-right: auto;
            ">
            <el-image
              :src="scope.row.imgUrl"
              :preview-src-list="[scope.row.imgUrl]"
            />
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="流程名称" align="center">
        <template #default="scope">
          <router-link :to="'/flowEdit?id=' + scope.row.id">
            {{ scope.row.name }}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" align="center" />
      <el-table-column prop="status" label="流程状态" align="center" />
      <el-table-column prop="remark" label="流程注释" align="center" />
      <el-table-column fixed="right" label="操作" align="center">
        <template #default="scope">
          <el-button link type="primary" size="small" @click="handleClick">
            详情
          </el-button>
          <el-button
            link
            type="primary"
            size="small"
            @click="toFlowDetail(scope.row)"
          >
            编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref, reactive, toRefs } from "vue";
import { useRouter } from "vue-router";
import { getFlowData } from "../api/flowApi.js";
const loading = ref(true);
const router = useRouter();
const tableData = ref([]);
const queryData = reactive({
  from: {},
  queryParams: {
    page: 1,
    limit: 10,
    flowName: undefined,
  },
  rules: {
    flowName: [
      { required: true, message: "公告标题不能为空", trigger: "blur" },
    ],
  },
});
const { from, queryParams, rules } = toRefs(queryData);

const indexMethod = (index) => {
  return index + 1;
};

const toFlowDetail = (row) => {
  router.push("/flowEdit?id=" + row.id);
};

const handleAdd = () => {
  router.push("/flowAdd");
};

const initData = () => {
  loading.value = true;
  getFlowData(queryParams.value).then((res) => {
    console.log(res);
    if (res.status === "0") {
      tableData.value = res.data.data;
    }
    loading.value = false;
  });
};

initData();

const handleQuery = () => {
  console.log("handleQuery");
};

const handleClick = () => {
  console.log("click");
};
</script>

<style>
.app-container {
  padding: 20px;
}
</style>